import axios from '@/libs/api.request'

export const login = ({ username, password }) => {
  const data = {
    username,
    password,
    'grant_type': 'password',
    'scope': 'app',
    'client_id': 'webApp',
    'client_secret': 'webApp'
  }
  return axios.request({
    url: 'http://47.98.183.130:8081/oauth/token',
    data,
    method: 'post'
  })
}

export const getUserInfo = (token) => {
  return axios.request({
    url: 'http://47.98.183.130:8080/users',
    params: {
      access_token: token
    },
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

export const logout = (token) => {
  return axios.request({
    url: 'http://47.98.183.130:8081/oauth/logout?access_token=' + token,
    method: 'get'
  })
}
